package com.apes.enquiry.supplier.baturu.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.MapUtil;
import com.apes.scm.masterdata.product.model.Product;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = BaturuInquireItem.CONST_TABLE_NAME)
public class BaturuInquireItem extends BaseModel {
    public static final String CONST_TABLE_NAME = "sp_buturu_inquire_item";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "巴图鲁-询价明细")
    @Comment("编号")
    private String id;

    @Comment("主表编码")
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "baturu_inquire_id", referencedColumnName = "id", nullable = false)
    private BaturuInquire baturuInquire;

    @Comment("配件名称")
    @Column(name = "parts_name", length = 60)
    private String partsName;

    @Comment("配件编码")
    @Column(name = "parts_code", length = 60)
    private String partsCode;

    @Comment("配件备注")
    @Column(name = "remark")
    private String remark;

    @Comment("配件图片地址")
    @Column(name = "pictures")
    private String pictures;

/*    @Comment("外部询价明细id")
    @Column(name = "external_inquiry_id", length=32)
    private String externalInquiryId;*/

    @Comment("商品编码")
    @Column(name = "origin_product_id", length=32)
    private String originProduct;

    @Column(name = "product_rule", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("带安标记")
    private boolean productRule;

    @Comment("平台编码")
    @Column(name = "platform_id", length=32)
    private String platformId;

    @Comment("三方明细编码")
    @Column(name = "three_party_detail_code", length=32)
    private String threePartyDetailCode;


    @OneToMany(mappedBy = "baturuInquireItem", cascade = CascadeType.ALL, orphanRemoval = true)
    private Set<BaturuInquireResult> baturuInquireResults = new HashSet<>();
    public Set<BaturuInquireResult> getBaturuInquireResults() {
        if (baturuInquireResults == null) return new HashSet<>();
       /* for (BaturuInquireResult result:baturuInquireResults) {
            result.setBaturuInquireItem(this);
        }*/
        return baturuInquireResults;
    }

}
